using System.Collections.Generic;
using System.Linq;
using TeamCityMonitor.Models;
using TeamCityMonitor.Repository;
using TeamCityMonitor.Repository.Caches;

namespace TeamCityMonitor.Manager
{
    public interface IBuildManager : IManager
    {
        List<ProjectModel> GetBuildModels();
        bool HasBuildsToShow();
    }

    public class BuildManager : IBuildManager
    {
        private IEnumerable<ProjectModel> troubledBuilds;
        private ITeamCityRepository repository;

        public BuildManager()
        {
            repository = new TeamCityRepository(new UserPictureRepository());
            troubledBuilds = repository.GetAllTroubledProjectModels();
        }

        public bool HasBuildsToShow()
        {
            return troubledBuilds.Any();
        }

        public List<ProjectModel> GetBuildModels()
        {
            return troubledBuilds.ToList();
        }

        public int GetNoOfFeedsToShowAtOnce()
        {
            return Properties.Settings.Default.FeedsToShowAtOnce;
        }

        public int GetFeedDelay()
        {
            return Properties.Settings.Default.FeedDelay;
        }
    }
}